//
//  SPAnnotationView.m
//  SPMapKit
//
//  Created by zhangbo on 2017/9/8.
//  Copyright © 2017年 zhangbo. All rights reserved.
//

#import "SPAnnotationView.h"

@implementation SPAnnotationView

-(instancetype) init
{
    if (self = [super init])
    {
        self.spAnnotationViewAlign = SPAlignCenter;
        self.isInteract = NO;
        self.canTouch = YES;
    }
    
    return self;
}

-(instancetype) initWithAnnotation:(id <SPAnnotation>) annotation
{
    if (self = [super init])
    {
        self.annotation = annotation;
        self.spAnnotationViewAlign = SPAlignCenter;
        self.isInteract = NO;
        self.canTouch = YES;
    }
    
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

-(CGRect) visibleFrame
{
    return self.frame;
}

@end


@implementation SPImageAnnotationView

-(instancetype) initWithAnnotation:(id <SPAnnotation>) annotation
{
    if (self = [super initWithAnnotation:annotation])
    {
        _imageView = [[UIImageView alloc] init];
        [self addSubview:_imageView];
    }
    
    return self;
}

-(void) sizeToFit
{
    CGRect frame = self.frame;
    frame.size = _imageView.image.size;
    self.frame = frame;
}

- (CGSize)sizeThatFits:(CGSize)size
{
    CGRect frame = self.frame;
    frame.size = _imageView.image.size;
    self.frame = frame;
    return frame.size;
}

- (void)layoutSubviews
{
    [_imageView sizeToFit];
//    _imageView.frame  = CGRectMake(_imageView.frame.size.width / 2.0,_imageView.frame.size.height / 2.0,CGRectGetWidth(_imageView.frame), CGRectGetHeight(_imageView.frame));
    _imageView.frame  = CGRectMake(0,0,CGRectGetWidth(_imageView.frame), CGRectGetHeight(_imageView.frame));
}

-(CGRect) visibleFrame
{
//    return CGRectMake(self.frame.origin.x + _imageView.frame.size.width / 2.0, self.frame.origin.y + _imageView.frame.size.height / 2.0, _imageView.frame.size.width, _imageView.frame.size.height);
    return CGRectMake(self.frame.origin.x , self.frame.origin.y , _imageView.frame.size.width, _imageView.frame.size.height);
}

@end
